//package com.ruoyi.system.controller;
package com.ruoyi.web.controller.shape;
import java.util.List;

import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.shape.domain.Shape;
import com.ruoyi.shape.service.IShapeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 手型、脸型信息Controller
 *
 * @author ruoyi
 * @date 2024-03-08
 */
@RestController
@RequestMapping("/shape")
public class ShapeController extends BaseController
{
    @Autowired
    private IShapeService shapeService;

    /**
     * 查询手型信息列表
     */
    @PreAuthorize("@ss.hasPermi('shape:getHandShapeList')")
    @GetMapping("/getHandShapeList")
    public TableDataInfo getHandShapeList(Shape shape)
    {
        startPage();
        List<Shape> list = shapeService.selectHandShapeList(shape);
        return getDataTable(list);
    }

    /**
     * 查询脸型信息列表
     */
    @PreAuthorize("@ss.hasPermi('shape:getHandShapeList')")
    @GetMapping("/getFaceShapeList")
    public TableDataInfo getFaceShapeList(Shape shape)
    {
        startPage();
        List<Shape> list = shapeService.selectFaceShapeList(shape);
        return getDataTable(list);
    }

    /**
     * 查询表所有信息列表
     */
    @PreAuthorize("@ss.hasPermi('shape:list')")
    @GetMapping("/list")
    public TableDataInfo list(Shape shape)
    {
        startPage();
        List<Shape> list = shapeService.selectShapeList(shape);
        return getDataTable(list);
    }

    /**
     * 导出手型、脸型信息列表
     */
    @PreAuthorize("@ss.hasPermi('shape:export')")
    @Log(title = "手型、脸型信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Shape shape)
    {
        List<Shape> list = shapeService.selectShapeList(shape);
        ExcelUtil<Shape> util = new ExcelUtil<Shape>(Shape.class);
        return util.exportExcel(list, "手型、脸型信息数据");
    }

    /**
     * 获取手型、脸型信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('shape:query')")
    @GetMapping(value = "getOne/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        Shape shape=shapeService.selectShapeById(id);
        if(shape!=null) {
            return AjaxResult.success(shapeService.selectShapeById(id));
        }else
            throw new CustomException("id为"+id + "的类型不存在");
//        return AjaxResult.success(shapeService.selectShapeById(id));
    }

    /**
     * 新增手型、脸型信息
     */
    @PreAuthorize("@ss.hasPermi('shape:add')")
    @Log(title = "手型、脸型信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Shape shape)
    {
        Shape shape1=new Shape();
        shape1.setName(shape.getName());
        List<Shape> list=shapeService.selectShapeList(shape1);
        if(list.size()>0) {
            throw new CustomException(shape.getName() + "类型已存在");
        }
        return toAjax(shapeService.insertShape(shape));
    }

    /**
     * 修改手型、脸型信息
     */
    @PreAuthorize("@ss.hasPermi('shape:edit')")
    @Log(title = "手型、脸型信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody Shape shape)
    {
        shape.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(shapeService.updateShape(shape));
    }

    /**
     * 删除手型、脸型信息
     */
    @PreAuthorize("@ss.hasPermi('shape:del')")
    @Log(title = "手型、脸型信息", businessType = BusinessType.DELETE)
	@PostMapping("/del/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shapeService.logicDeleteShape(ids,DicConstants.BUSINESS_Manager.getCode(),SecurityUtils.getUserId()));
    }
}
